import pandas as pd
import numpy as np
import os
import sys
import model_code.gen_data as gd
import model_code.rfg as rfg
import model_code.per_mea as pm
from tensorflow import keras

source = sys.argv[1]
pre_time = sys.argv[2]
ioh_time = sys.argv[3]
ob_win = sys.argv[4]

pre_time = int(pre_time)
pre_time = pre_time / 5
ob_win = int(ob_win)

d_path = source + "/dynamic_normalization/" + ioh_time + "-bt.csv"
s_path = source +"/" +"static/test_case.csv"
c_path = "config_bt.json"

static, dynamic, label = gd.gen_data(source, d_path, c_path, s_path, pre_time, ob_win)
dynamic_dim = dynamic.reshape(dynamic.shape[0], dynamic.shape[1], dynamic.shape[2], 1)

model_path = "models/tongji+BT-1.0-1-5.h5"

model = keras.models.load_model(model_path, custom_objects={"AUC": pm.AUC})

y_pred = model.predict([dynamic_dim, dynamic])
y_true = label

print("AUC: " + str(pm.AUC(y_true, y_pred)))
print("precision: " + str(pm.precision(y_true, y_pred)))
print("recall: " + str(pm.recall(y_true, y_pred)))
print("sensitivity: " + str(pm.TPR(y_true, y_pred)))
print("specificity: " + str(pm.TNR(y_true, y_pred)))  
print("F1: " + str(pm.F1(y_true, y_pred)))
print("accuracy: " + str(pm.accuracy(y_true, y_pred)))
